package cn.darksoul3.springcloud.alibaba.controller;


import cn.darksoul3.common.result.ObjectResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;


@Slf4j
@RefreshScope
@RestController
public class Tok {

    @Value("${server-url.nacos-user-service}")
    private String svcUrl;
    @Value("${config.version}")
    private String ver;
    private final RestTemplate rest;

    @Autowired
    public Tok(RestTemplate rest) {
        this.rest = rest;
    }

    @GetMapping("/tok")
    public ObjectResult nacosTok(){
        log.info("this is nacos tok");
        return rest.getForObject(svcUrl+"/tick",ObjectResult.class);
    }

    @GetMapping("/config")
    public ObjectResult nacosConfig(){
        log.info("this is nacos config");
        return ObjectResult.succeed(this.ver);
    }

}
